import java.util.ArrayList;
import java.util.InputMismatchException;
import java.util.Random;
import java.util.Scanner;

public class randomName {
    public static void main(String[] args) throws AgeException {

        ArrayList<Student> students = new ArrayList<Student>();
        addStudentName(students);
        printStudentsName(students);
        String randName=randStudentName(students);
        System.out.println("Lucky dog: "+randName);
    }

    public static void addStudentName(ArrayList<Student> students) throws AgeException {
        Scanner sc=new Scanner(System.in);
        for(int i=0;i<3;i++){
            Student s = new Student();
            System.out.println("存储第"+(i+1)+"个名称");
            s.setId(i+1);
            System.out.println("name");
            s.setName(sc.next());
            System.out.println("age");
            try{
                s.setAge(sc.nextInt());
            }catch (InputMismatchException e){
                throw new AgeException("输入的年龄格式不正确，必须是一个整数。");
            }
            students.add(s);
        }

    }
    private static void printStudentsName(ArrayList<Student> students) {
        for(int i=0;i<students.size();i++){
            Student s = students.get(i);
            System.out.println("第"+(i+1)+"个学生id："+s.getId());
            System.out.println("第"+(i+1)+"个学生age："+s.getAge());
            System.out.println("第"+(i+1)+"个学生名称："+s.getName());
        }

    }
    public static String randStudentName(ArrayList<Student> students){
        Random random = new Random();
        int index=random.nextInt(students.size());
        Student s = students.get(index);
        return s.getName();
    }


}
//改抽学生
